import { parse } from 'url';
import { TableListData, TableListItem, TableListParams } from './data';

function getExpressInfo(
  req: { url: any },
  res: {
    json: (
      arg0: {code: number, body: TableListData },
    ) => void;
  },
  u: any,
) {
  let new_url = u;
  if (!new_url || Object.prototype.toString.call(new_url) !== '[object String]') {
    new_url = req.url;
  }

  const count = 50;

  const params = (parse(new_url, true).query as unknown) as TableListParams;
  const { pageIndex, pageSize } = params;
  const starNum = (pageIndex - 1) * pageSize;
  const endNum = pageIndex * pageSize;

  const dataSource: TableListItem[] = [];

  [...new Array(endNum - starNum)].map((item: TableListItem, index: number) => (
    dataSource.push({
      id: starNum + index + 1,
      createTime: '2019-10-20',
      updateTime: '2019-10-20',
      logisId: 4,
      expressId: 2,
      expressName: '申通快递',
      expressPhone: '95543',
      setWorkMode: 1,
      workMode: 1,
      setWorkModeName: '合并流程（接驳分拣合并）',
      workModeName: '合并流程（接驳分拣合并）',
    })
  ));

  const result = {
    code: 0,
    body: {
      list: dataSource,
      count,
    },
  };

  return res.json(result);
}

export default {
  'GET /logis/logisExpressList': getExpressInfo,
};
